/**
 * Created by zbcx on 2017/6/14.
 */
namespace("cx.test.test");

cx.test.test = function () {

    /**
     *
     * @param container         地图的显示容器
     * @param opts
     */
    var constructor = function (container, opts) {
        this.map = null;
        this.container = container;
        this.opts = opts;

        this.map = new T.Map(container, opts);
        this.map.wrap = this;

        this.setCenterAndZoom(opts.center, opts.zoom);
    };

    /**
     * @method setCenterAndZoom
     * 设置地图的中心和显示级别
     * @param {cx.coordinate}   lnglat  经纬度对象
     * @param {Number}          zoom    要显示的地图级别
     */
    var setCenterAndZoom = function (lnglat, zoom) {
        this.map.centerAndZoom(new T.LngLat(121.47, 31.23), 12);
    };

    var addOverlay = function (overlay) {
        if (overlay instanceof cx.test.Overlay) {
            if (cx.test.isBaiDuMap()) {
                this.map.addOverlay(overlay.getCore());
            }
            else if (cx.test.isTianMap()) {
                this.map.addOverLay(overlay.getCore());
            }
        }
    };

    var start = function () {
        console.log(1111);
    }
    var destroy = function () {
        console.log(22222);
    };

    cx.inherits(constructor, cx.frm.PluginBase);
    var prototype = constructor.prototype;
    prototype.setCenterAndZoom = setCenterAndZoom;
    prototype.addOverlay = addOverlay;
    prototype.start = start;

    constructor.destroy = destroy;
    return constructor;
}();


//使用两个字符串参数，name 和 teacher
function Lecture(name, teacher) {
//把它们作为对象的本地属性保存
    this.name = name;
    this.teacher = teacher;
}

Lecture.prototype.display = function () {
    return this.teacher + " is teaching " + this.name;
};

function Schedule(lectures) {
    this.lectures = lectures;
}
//类 Schedule 的方法，用来构造一个描述该课程表的字符串
Schedule.prototype.display = function () {
    var str = "";
//遍历每门课程，累加构成信息字符串
    for (var i = 0; i < this.lectures.length; i++)
        str += this.lectures[i].display() + " ";
    return str;
};


function addGenerator(num) {
//返回一个简单函数用来计算两个数的加法，
//其中第一个数字从生成器中借用
    return function (toAdd) {
        return num + toAdd
    };
}


//创建一个用作包装的匿名函数
(function () {
//这个变量通常情况下应该是全局的
    var msg = "Thanks for visiting!";
//为全局对象绑定新的函数
    window.onunload = function () {
//使用了“隐藏”的变量
        alert(msg);
    };
//关闭匿名函数并执行之
})();


var obj = {
    yes: function () {
        this.val = true;
    },
    no: function () {
        this.val = false;
    }
}

// 如果没有定义一些基类可以暂时使用把公用的方法，像以下方式挂到对象上
var objCacheZCJ = function () {
    var constract = function () {
    };
    var setZCJ = function (a) {
        console.log(a);
    };
    constract.setZCJ = setZCJ;
    return constract;
}();

